package com.oamicnet;

import com.baomidou.mybatisplus.core.MybatisSqlSessionFactoryBuilder;
import com.oamicnet.mapper.UserMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import java.io.IOException;
import java.io.InputStream;

public class App {
    public static void main(String[] args) throws IOException {
        //获取配置文件
        InputStream stream = Resources.getResourceAsStream("mybatis-config.xml");
        //通过SqlSessionFactoryBuilder加载配置文件创建SqlSessionFactory
//        SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(stream);
        SqlSessionFactory sessionFactory = new MybatisSqlSessionFactoryBuilder().build(stream);
        //打开SqlSession
        SqlSession sqlSession = sessionFactory.openSession();
        //获取mapper对象
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);

        //执行方法
//        int result = mapper.insert();
//        System.out.println("result" + result);

        //提交事务
        sqlSession.commit();
        sqlSession.close();
//        System.out.println(result);
    }
}
